package com.tbi.graphcolouring.algorithmconfiguration.selector;

import java.util.Collections;
import java.util.ArrayList;
import java.util.List;

import com.tbi.algorithm.configuration.ISelector;
import com.tbi.graphcolouring.AlgorithmSettings;
import com.tbi.graphcolouring.PopulationEntity;
import com.tbi.graphcolouring.utils.Random;

public class ExponentialRankingSelector implements ISelector{

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void selection(List population) {
		ArrayList<PopulationEntity> newPopulation = new ArrayList<>();
		int populationSize = population.size();
		Collections.sort(population);
		
		for(int i = 0; i<populationSize*AlgorithmSettings.SELECTION_FACTOR; i++){
			PopulationEntity entity = (PopulationEntity) population.remove((int)(Random.scaledExponential(populationSize - (i + 1))));
			newPopulation.add(entity);
		}
		
		population.clear();
		population.addAll(newPopulation);
	}

}